package com.chinanet.repository.faultanticipate.manager;


import com.chinanet.entry.faultanticipate.manager.QTeam;
import com.chinanet.entry.faultanticipate.manager.Team;
import com.querydsl.core.types.dsl.StringPath;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.querydsl.binding.QuerydslBinderCustomizer;
import org.springframework.data.querydsl.binding.QuerydslBindings;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.io.UnsupportedEncodingException;

public interface TeamRepository extends PagingAndSortingRepository<Team, Long>, QuerydslBinderCustomizer<QTeam> ,QuerydslPredicateExecutor<Team> {

    // 过滤
    default void customize(QuerydslBindings bindings, QTeam team) {
/*        bindings.bind(relation.name).first((path, value) -> path.contains(value));
        bindings.bind(relation.name).first((path, value) -> path.containsIgnoreCase(value));*/
        bindings.bind(String.class).first((StringPath path, String value) -> {
            // 中文乱码解决问题
            try {
                String newValue=new String(value.getBytes("iso-8859-1"),"utf-8");
                return  path.contains(newValue);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return  null;
            }
        });
    }
}